package com.h3c.tj_nsh.UI.MVP.Engineer;

import android.support.v4.app.FragmentActivity;
import android.util.Log;

import com.h3c.tj_nsh.Model.ProcessDefinition;
import com.h3c.tj_nsh.Model.ProcessDefinitionList;
import com.h3c.tj_nsh.MyApplication;
import com.h3c.tj_nsh.Net.ITSM_API;
import com.h3c.tj_nsh.Net.NetWork;
import com.h3c.tj_nsh.Utils.UIUtils;

import java.io.IOException;
import java.util.List;

import retrofit.Call;
import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;

/**
 * Time: 2016/5/13.
 * Author:Chen  .
 */
public class ITSM_Present {
    private ITSM_View_En mITSM_view;
    private MyApplication mApp;
    private static final String TAG = "ITSM_Present";

    public ITSM_Present(ITSM_View_En v) {
        this.mITSM_view = v;
        mApp = (MyApplication) v.getContext().getApplicationContext();
    }

    public void openItemActivity(FragmentActivity activity, String itemLaber) {
        switch (itemLaber) {
            case "业务需求":
                break;
            case "设备测试":
                break;
            case "数据提取":
                break;
            case "数据修改":
                break;
            case "服务申请":
                UIUtils.showITSMServiceRequest(activity);

                break;
            case "资源申请":
                break;
            case "物理权限":
                break;
            case "IT日常事项":
                break;
            case "变更请求":
                break;
            case "发布请求":
                break;

        }

    }

    public void getProcessDefinitionList() {

        if (mApp.getProcessDefinitionList() == null) {
            try {
                ITSM_API itsmApi = NetWork.getITSMApi();
                Call<ProcessDefinitionList> processDefinition = itsmApi.getProcessDefinition();
                processDefinition.enqueue(new Callback<ProcessDefinitionList>() {
                    @Override
                    public void onResponse(Response<ProcessDefinitionList> response, Retrofit retrofit) {
                        if (response.code() == 200) {
                            if (mApp.getProcessDefinitionList() == null) {
                              mApp.setProcessDefinitionList(response.body());
                            }
                        } else {
                            Log.e(TAG, response.message() + response.errorBody());
                        }
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        Log.e(TAG, t.getMessage());
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }


}
